package org.light.reflecttable.serviceimpl;

import java.sql.Connection;
import java.util.List;

import org.light.reflecttable.dao.DatabaseDao;
import org.light.reflecttable.dao.FieldDao;
import org.light.reflecttable.daoimpl.DatabaseDaoImpl;
import org.light.reflecttable.daoimpl.FieldDaoImpl;
import org.light.reflecttable.database.DBConf;
import org.light.reflecttable.domain.Database;
import org.light.reflecttable.service.DatabaseService;

public class DatabaseServiceImpl implements DatabaseService{
	protected DatabaseDao dao = new DatabaseDaoImpl();
	protected FieldDao fieldDao = new FieldDaoImpl();
		
	public List<Database> listAllDatabases() throws Exception{
		String dbLink = TableServiceImpl.dbLink;
		String dbHost = TableServiceImpl.dbHost;
		String dbPort = TableServiceImpl.dbPort;
		String dbName = TableServiceImpl.dbName;
		String userName = TableServiceImpl.userName;
		String password = TableServiceImpl.password;
		try (Connection connection = DBConf.initMariaMetaDB(dbHost,dbPort,dbName,userName,password)) {
			return dao.listAllDatabases(connection);
		}
	}

	@Override
	public List<Database> listAllPgDatabases() throws Exception {
		String dbLink = TableServiceImpl.dbLink;
		String dbHost = TableServiceImpl.dbHost;
		String dbPort = TableServiceImpl.dbPort;
		String dbName = TableServiceImpl.dbName;
		String userName = TableServiceImpl.userName;
		String password = TableServiceImpl.password;
		try (Connection connection = DBConf.initPgMetaDB(dbHost,dbPort,dbName,userName,password)) {
			return dao.listAllPgDatabases(connection);
		}
	}
}
